cssimage: Handle 0x0 images
authorBenjamin Otte <otte@redhat.com>
Tue, 15 Dec 2015 20:23:59 +0000 (21:23 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 16 Dec 2015 00:50:00 +0000 (01:50 +0100)
0x0 images can happen when we fail to load an image - or when we
successfully load a 0x0 image.

gtk/gtkcssimagesurface.c

index ac812ddcb0fb932664829f27393690867c90bdfa..1570e83bedcd3f6784c7728f63821f9e7eba38bf 100644 (file)
@@ -46,11 +46,18 @@ gtk_css_image_surface_draw (GtkCssImage *image,
                             double       height)
 {
   GtkCssImageSurface *surface = GTK_CSS_IMAGE_SURFACE (image);
+  int image_width, image_height;
+
+  image_width = cairo_image_surface_get_width (surface->surface);
+  image_height = cairo_image_surface_get_height (surface->surface);
+
+  if (image_width == 0 || image_height == 0)
+    return;
 
   cairo_rectangle (cr, 0, 0, width, height);
   cairo_scale (cr,
-               width / cairo_image_surface_get_width (surface->surface),
-               height / cairo_image_surface_get_height (surface->surface));
+               width / image_width,
+               height / image_height);
   cairo_set_source_surface (cr, surface->surface, 0, 0);
   cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
   cairo_fill (cr);